package com.integralPerformance.handler;

import com.integralPerformance.common.Result;
import com.integralPerformance.exception.ServiceNameException;
import com.integralPerformance.exception.TeacherNameException;
import com.integralPerformance.exception.TestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    private final static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(TestException.class)
    public Result<?> handleJobNumberNotExistException(){
        return Result.fail(108,"测试",null);
    }

    @ExceptionHandler(TeacherNameException.class)
    public Result<?> handleTeacherNameNotExistException(){
        return Result.fail(404,"该教师未找到",null);
    }

    @ExceptionHandler(ServiceNameException.class)
    public Result<?> handleServiceNameNotExistException(){
        return Result.fail(404,"该类型未找到",null);
    }


    //假装 只有默认出错的错误状态码为201
    @ExceptionHandler(value = RuntimeException.class)
    public  Result<?> BaseException(RuntimeException e){
        e.printStackTrace();
        logger.error(e.getMessage());
        return Result.fail(e.getMessage());
    }

}
